/**
 * Bob.Ren
 * 2013-8-3
 */
package com.noqueue.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.noqueue.dao.QueueListPagerEateryDao;
import com.noqueue.entity.Customer;
import com.noqueue.entity.QueueListPagerEntity;

/**
 * @author Bob.Ren
 * @date 2013-8-3
 */
@Repository
public class QueueListPagerEateryDaoImpl extends
		BaseDaoImpl<QueueListPagerEntity, String> implements
		QueueListPagerEateryDao {

	@SuppressWarnings("unchecked")
	public List<QueueListPagerEntity> loadEntityByEateryId(String eateryId) {
		String sql = "select new com.noqueue.entity.QueueListPagerEntity(cq.customer.customerName ,cq.customer.sex ,cq.customer.callType ,cq.customer.callName ,cq.amount ,cq.peoples ,cq.isInform)  from  CustomerQueue cq where cq.eateryId = ? and cq.isDine = 0";
		return getSession().createQuery(sql).setParameter(0, eateryId).list();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.noqueue.dao.QueueListPagerEateryDao#getNextInformCustomer()
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Customer getNextInformCustomerByEateryId(String eateryId) {
		String sql = "select new com.noqueue.entity.Customer(cq.customer.customerName,cq.customer.sex,cq.customer.callType,cq.customer.callName) from CustomerQueue cq where cq.isInform = 0 and cq.eateryId = ? order by cq.amount asc";
		List<Customer> list = getSession().createQuery(sql)
				.setParameter(0, eateryId).list();
		return list.size() > 0 ? list.get(0) : null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.noqueue.dao.QueueListPagerEateryDao#getNextDineCustomerByEateryId
	 * (java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Customer getNextDineCustomerByEateryId(String eateryId) {
		String sql = "select new com.noqueue.entity.Customer(cq.customer.customerName,cq.customer.sex,cq.customer.callType,cq.customer.callName) from CustomerQueue cq where cq.eateryId = ? and cq.isDine = 0 order by cq.amount asc";
		List<Customer> list = getSession().createQuery(sql)
				.setParameter(0, eateryId).list();
		return list.size() > 0 ? list.get(0) : null;
	}
}
